package com.keepers.repair.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.keepers.repair.helper.SpHelper;
import com.keepers.repair.mina.ConnectionConfig;
import com.keepers.repair.mina.ConnectionManager;
import com.keepers.repair.net.HttpUtil;

/**
 * auth aboom
 * date 2018/12/11
 */
public class MinaService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initSocket();
    }

    private void initSocket() {
        if (SpHelper.getLoginUserInfo() == null) {
            return;
        }

        String currentHttpHost = SpHelper.getCurrentHttpHost();
        if (TextUtils.isEmpty(currentHttpHost)) {
            currentHttpHost = HttpUtil.HTTP_HOST;
        }
        ConnectionConfig config = new ConnectionConfig.Builder().setIp(currentHttpHost).setPort(7000).builder();
        ConnectionManager connectionManager = new ConnectionManager(config);
        connectionManager.connect();
    }
}
